package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Entity?remove_ending(".po")}.vo.Get${entity?remove_ending("PO")}ListVO;
import ${package.Entity?remove_ending(".po")}.dto.Save${entity?remove_ending("PO")}DTO;
import ${package.Entity?remove_ending(".po")}.dto.DeleteCommonDTO;
import ${package.Entity?remove_ending(".po")}.converter.${entity?remove_ending("PO")}Converter;
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import ${package.Entity?remove_ending(".entity.po")}.common.vo.FilteredParameter;
import ${package.Entity?remove_ending(".entity.po")}.common.vo.RespVO;
import ${package.Entity?remove_ending(".entity.po")}.common.vo.ApiResultCode;
import ${package.Entity?remove_ending(".entity.po")}.utils.FilteredUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ${table.comment!} 服务类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Override
    public RespVO<List<Get${entity?remove_ending("PO")}ListVO>> get${entity?remove_ending("PO")}List(FilteredParameter dto) {
        QueryWrapper<${entity}> queryWrapper = FilteredUtil.getQueryWrapper(dto);
        IPage<${entity}> iPage = page(FilteredUtil.getPage(dto), queryWrapper);
        return RespVO.success(${entity?remove_ending("PO")}Converter.INSTANCE.get${entity?remove_ending("PO")}ListVos(iPage.getRecords()), iPage.getTotal());
    }


    @Override
    public RespVO<Object> add${entity?remove_ending("PO")}(Save${entity?remove_ending("PO")}DTO dto) {
        ${entity} ${entity?uncap_first?remove_ending("PO")}Info = ${entity?remove_ending("PO")}Converter.INSTANCE.get${entity?remove_ending("PO")}Po(dto);
        boolean add = save(${entity?uncap_first?remove_ending("PO")}Info);
        if (!add) {
            return RespVO.success(RespVO.failure(ApiResultCode.G500, "新增失败"));
        }
        return RespVO.success("新增成功");
    }

    @Override
    public RespVO<Object> update${entity?remove_ending("PO")}(Save${entity?remove_ending("PO")}DTO dto) {
         ${entity} ${entity?uncap_first?remove_ending("PO")}Info = ${entity?remove_ending("PO")}Converter.INSTANCE.get${entity?remove_ending("PO")}Po(dto);
         updateById(${entity?uncap_first?remove_ending("PO")}Info);
         return RespVO.success("保存成功");
    }

    @Override
    public RespVO<Object> save${entity?remove_ending("PO")}(Save${entity?remove_ending("PO")}DTO dto){
        ${entity} ${entity?uncap_first?remove_ending("PO")}Info = ${entity?remove_ending("PO")}Converter.INSTANCE.get${entity?remove_ending("PO")}Po(dto);
        boolean save = saveOrUpdate(${entity?uncap_first?remove_ending("PO")}Info);
        if (!save) {
            return RespVO.success(RespVO.failure(ApiResultCode.G1100, "未修改信息"));
        } else {
            if (Objects.isNull(dto.get<#list table.fields as field><#if field.keyFlag>${field.propertyName?cap_first}</#if></#list>())) {
                return RespVO.success("新增成功");
            } else {
                return RespVO.success("修改成功");
            }
        }
    }

    @Override
    public RespVO<Object> removes${entity?remove_ending("PO")}(DeleteCommonDTO dto) {
        List<Long> idList = dto.getIdList();
        boolean remove = removeByIds(idList);
        if (!remove) {
           return RespVO.success(RespVO.failure(ApiResultCode.G500, "删除失败"));
        }
        return RespVO.success("删除成功");
    }
}
</#if>
